package org.shangma;

import io.seata.spring.boot.autoconfigure.SeataTCCFenceAutoConfiguration;
import org.shangma.interceptor.XIDInterceptor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.web.client.RestTemplate;

import java.util.List;

// 新版TCC模式，需要数据源，但这个模块不需要数据源，所以排除TCC的自动配置
@SpringBootApplication(exclude = SeataTCCFenceAutoConfiguration.class)
@EnableFeignClients
public class XaBusinessApp {

    public static void main(String[] args) {
        SpringApplication.run(XaBusinessApp.class);
    }

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate(){
//        RestTemplate restTemplate = new RestTemplate();
//        List<ClientHttpRequestInterceptor> interceptors = restTemplate.getInterceptors();
//        interceptors.add(new XIDInterceptor());
//        restTemplate.setInterceptors(interceptors);
//        return restTemplate;
        return new RestTemplate();
    }
}
